// pages/login/login.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    second:'获取验证码',
    isClick:false,
    phone:'',
    code:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  saoma:function(){
    var that = this;
    wx.request({
      url: app.baseurl+'user/login',
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      data:{"mobile":that.data.phone,"code":that.data.code},
      dataType:'json',
      success:function(res){
        wx.setStorage({
          key: 'token',
          data: res.data.token,
        })
        wx.redirectTo({
          url: '../saoma/sapma',
        })
        console.log(res.data)
        
      },
      fail:function(e){
        console.log(e)
      }
    })
    
    
  },
  getphone:function(e){
    console.log(e)
    this.setData({
      phone:e.detail.value
    })
  },
  getYzCode:function(e){
    var text =  60;
    var that = this;
    
    if(!that.data.isClick){
      that.setData({
        isClick: true
      })
      var timer = setInterval(function () {
        text--
        that.setData({
          second: '剩余' + text + '秒'
        })
        if (text == 0) {
          clearInterval(timer);
          that.setData({
            isClick: false,
            second:'点击重新获取'
          })
        }
        
      }, 1000)
    }
    wx.request({
      url: app.baseurl+'user/getCode/'+that.data.phone,
      method: 'GET',
      success:function(res){
        console.log(res.data)
        console.log(res.data.data.code)
        that.setData({
          code: res.data.data.code+''
        })
      }
    })
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})